package team.niit.bean;

import cn.hutool.core.bean.BeanUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import team.niit.entity.StudentEntity;
import team.niit.service.StudentService;
import team.niit.service.impl.StudentServiceImpl;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import java.util.List;

/**
 * @Author: 然然然儿呐_
 * @Project_name: stu_select_course
 * @Package_name: team.niit.bean
 * @Date: 2021/10/21 15:34
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ManagedBean(name = "student")
@SessionScoped
public class StudentBean {
    /**
     * 编号
     */
    private String id;

    /**
     * 姓名
     */
    private String name;

    /**
     * 性别
     */
    private String gender;

    /**
     * 生日
     */
    private String birth;

    /**
     * 学院
     */
    private String school;

    /**
     * 专业
     */
    private String major;

    /**
     * 班级
     */
    private String classes;

    /**
     * 密码
     */
    private String password;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 注册时候的第二个密码
     */
    private String newPassword;

    private List<StudentEntity> studentEntityList;

    StudentService studentService = new StudentServiceImpl();

    /**
     * 105：学生修改个人信息
     * @return
     */
    public String modifyStudentById(Object o) {
        StudentEntity studentEntity =  new StudentEntity();
        BeanUtil.copyProperties(o, studentEntity);
        studentService.modifyStudentById(studentEntity);
        return "student_view_info";
    }

    /**
     * 管理员修改学生信息
     * @return
     */
    public String adminModifyStudentInfo(Object o) {
        StudentEntity studentEntity =  new StudentEntity();
        BeanUtil.copyProperties(o, studentEntity);
        studentService.modifyStudentById(studentEntity);
        return "/pages/admin/admin_view_all_student";
    }


    /**
     * 跳转管理员修改学生信息
     * @param studentEntity
     * @return
     */
    public String goToAdminModifyInfo(StudentEntity studentEntity) {
        BeanUtil.copyProperties(studentEntity, this);
        return "admin_modify_student_info";
    }
}
